package com.txzt.gaea.config.dm;

import org.beetl.sql.core.annotatoin.AssignID;
import org.beetl.sql.core.annotatoin.AutoID;
import org.beetl.sql.core.annotatoin.SeqID;
import org.beetl.sql.core.db.AbstractDBStyle;
import org.beetl.sql.core.kit.BeanKit;

import java.lang.annotation.Annotation;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

public class DmStyle extends AbstractDBStyle {
    @Override
    public String getName() {
        return "dm";
    }

    @Override
    public int getDBType() {
        return 10;
    }

    public String getPageSQL(String sql) {
        return sql + this.getOrderBy() + " \nlimit " + this.HOLDER_START + "_pageOffset" + this.HOLDER_END + " , " + this.HOLDER_START + "_pageSize" + this.HOLDER_END;
    }

    public String getPageSQLStatement(String sql, long offset, long pageSize) {
        offset = PageParamKit.mysqlOffset(this.offsetStartZero, offset);
        StringBuilder builder = new StringBuilder(sql);
        builder.append(" limit ").append(offset).append(" , ").append(pageSize);
        return builder.toString();
    }

    public void initPagePara(Map<String, Object> param, long start, long size) {
        param.put("_pageOffset", start - (long)(this.offsetStartZero ? 0 : 1));
        param.put("_pageSize", size);
    }

    public int getIdType(Class c, String idProperty) {
        List<Annotation> ans = BeanKit.getAllAnnoation(c, idProperty);
        int idType = 2;
        Iterator var5 = ans.iterator();

        while(var5.hasNext()) {
            Annotation an = (Annotation)var5.next();
            if (an instanceof AutoID) {
                idType = 2;
                break;
            }

            if (!(an instanceof SeqID) && an instanceof AssignID) {
                idType = 1;
            }
        }

        return idType;
    }
}
